<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--#include file="DataLoad.asp"-->
<%Call CheckAdmin2()%>

<html>
<head>
<title><%=GuildName%> - DKP系统</title>
<script language="JavaScript" src="inc/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Generator" content="EditPlus">
<meta name="Author" content="SULei">
<meta name="Keywords" content="DKP WOW GUILD">
<meta name="Description" content="">
<link href="<%=StylePath%>/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="<%=StylePath%>/styleplus.js"></script>
<style type="text/css" media="all">
	td {font-family:;}
</style>

<!DOCTYPE html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title> New Document </title>
<script language="JavaScript" src="inc/jquery.js"></script>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="SULei">
<meta name="Keywords" content="">
<meta name="Description" content="">
<style type="text/css" media="all">

</style>
</head>

<body>

</body>
</html>
</head>

<body>
<%

Select Case Request("Action")
	Case "Form"
		Call ImportForm()
	Case "Post"
		Dim raidTime , raidNote
		Dim playerName , playerRace , playerClass , playerLevel , playerJoinTime
		Dim leavePlayerName , leavePlayerTime
		Dim itemName , itemID , itemColor , itemCount , itemLooter , itemLootTime , itemNote
		Dim ChildrenCount
		Dim arrPlayerList , arrLeavePlayerList , arrLeavePlayerTime
		Dim RaidID , RaidEndTime
		'有表单数据就覆盖旧缓存文件
		if not (request.form("xmltext")="") then
			Call WriteFile ("Renew.xml",request.form("xmltext"))
		end if
		'建立DOM对象
		Set rXML = server.CreateObject("MSXML.DOMDocument") 
		rXML.load server.MapPath("xml/Renew.xml") 
		Set rtXML=rXML.documentelement 

		'建立DOM对象B
		Set sXML = server.CreateObject("MSXML.DOMDocument") 
		sXML.load server.MapPath("xml/Renew.xml") 
		Set stXML=sXML.documentelement 

	if isNull(rXML.getElementsByTagName("Leave")(0).childNodes) or isNull(rXML.getElementsByTagName("Loot")(0).childNodes) or isNull(rXML.getElementsByTagName("Join")(0).childNodes) then
		Response.write "数据不完整,无法进行处理. 可能是由于缺少拾取物品或离开人员的有关信息."
	else
		Set playerXML=rXML.getElementsByTagName("Join")(0).childNodes
		Set leaveplayerXML=rXML.getElementsByTagName("Leave")(0).childNodes
		Set LootXML=rXML.getElementsByTagName("Loot")(0).childNodes

		Set playerXMLs=sXML.getElementsByTagName("Join")(0).childNodes

		Call ImportPost()
		Response.write "<h3>数据已经自动导入,请在确认无误后报告结果.</h3>"
		Response.write "<h3 id='menu'><a href=''>活动</a> - <a href='admin_report.asp?action=collect&id="&RaidID&"'>人员</a> - <a href='admin_report.asp?action=collect2&id="&RaidID&"'>事件</a> - <a href='raid_report.asp?id="&RaidID&"'>报告</a></h3>"
	end if
	Case Else
		Call ImportMenu()
End Select
%>


<%
Sub ImportMenu()
	Response.write "<a href='?Action=Form'>数据恢复</a>"
	Response.write " | <a href='?Action=Post'>查看分析结果</a>"
End Sub

Sub ImportForm()
Response.write "<form method='post' action='?Action=Post'>粘贴要恢复的备份数据.<br/>"
Response.write "	<textarea name='xmltext' rows='30' cols='80'></textarea>"
Response.write "	<input type='submit' value='提交处理' />"
Response.write "<br>系统会缓存最近一次提交的数据到 xml/Renew.xml 文件中"
Response.write "</form>"
End Sub








%>
</body>
</html>


<%
Sub ImportPost()
	Response.write "<h1>活动主题: "&rtXML.childNodes.item(1).text&"</h1>"


	Response.write IsObject(rXML.getElementsByTagName("Loot")(0).childNodes)

	'Response.write "<h2>Time:( "&DateE2C(rtXML.childNodes.item(0).text)&" - "&CDate(DateE2C(rtXML.childNodes.item(3).lastchild.childNodes.item(1).text))&" )</h2>"&vbCrlf
	'调用方法
		Call CTRT_Player()
		Call CTRT_Leave()
		Call CTRT_Loot()
		Call FSDKP_Event()
End Sub




Sub CTRT_Player() '参与相关处理|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
	Response.write "<table class='dkplist'>"&vbCrlf
	Response.write "<tr><th colspan='6'>Raid Player List</th></tr>" &vbCrlf
	Response.write "<tr><th>Number</th><th>Name</th><th>Race</th><th>Class</th><th>Level</th><th>JoinTime</th></tr>"&vbCrlf
'-----------------清理玩家表中重复的和信息不全的条目
	ChildrenCount = rtXML.childNodes.item(2).childNodes.length-1
	arrPlayerList=","
	for i = 0 to ChildrenCount 
		if playerXML.item(i).childNodes.length<5 then
			rtXML.childNodes.item(2).removeChild(playerXML.item(i))
			ChildrenCount=ChildrenCount-1
			i=i-1
		else
			if Instr(arrPlayerList,","&playerXML.item(i).childNodes.item(0).text&",")>0 then
				rtXML.childNodes.item(2).removeChild(playerXML.item(i))
				ChildrenCount=ChildrenCount-1
				i=i-1
			else
				arrPlayerList=","&playerXML.item(i).childNodes.item(0).text&arrPlayerList
			end if
		end if
		if i=ChildrenCount then exit for
	next
'-----------------清理结束
	'@@@@@@@@@@建立Raid 或修改已有的Raid信息
	sql = "select * from raid where raid_concentratetime=#"&CDate(rtXML.childNodes.item(0).text)&"#"
	rs.open sql,conn,1,3
	if rs.eof or rs.bof then
		rs.close
		sql = "select * from raid where (id is null)"
		rs.open sql,conn,1,3
			rs.addnew
			rs("raid_name")=rtXML.childNodes.item(1).text
			rs("raid_concentratetime")=CDate(rtXML.childNodes.item(0).text)
			rs("raid_actiontime")=CDate(rtXML.childNodes.item(0).text)
			rs("raid_endtime")=CDate(rXML.getElementsByTagName("Extra")(0).getElementsByTagName("Endtime")(0).text)
			rs("raid_personnel")=40
			rs("raid_class")=1
			rs("raid_player")=""
			if rs("raid_step")=0 then
			rs("raid_step")=1
			rs("raid_ruler")=1
			end if
			rs.update
	'	response.write "添加新记录"
	else
		RaidID=rs("id")
			rs("raid_name")=rtXML.childNodes.item(1).text
			'rs("raid_concentratetime")=CDate(DateE2C(rtXML.childNodes.item(0).text))
			'rs("raid_actiontime")=DateAdd("n",30,CDate(DateE2C(rtXML.childNodes.item(0).text)))
			'rs("raid_endtime")=CDate(DateE2C(rtXML.childNodes.item(3).lastchild.childNodes.item(1).text))
			if rs("raid_step")=0 then
			rs("raid_step")=1
			end if
			rs("raid_ruler")=1
			rs.update
	'	response.write "修改存在记录"
	end if
	rs.close

'取得RaidID
	sql = "select * from raid where raid_concentratetime=#"&CDate(rtXML.childNodes.item(0).text)&"#"
	rs.open sql,conn,1,3
	RaidID=rs("id")
	RaidEndTime=rs("raid_endtime")
	rs.close

'删除此Raid全部事件,重新计算
sql="Delete * from raid_event where event_raidid="&RaidID
conn.execute (sql)


	Sql="Select * from raid_event where (id is null)"
	rs2.open sql,conn,1,3
	ChildrenCount = rtXML.childNodes.item(2).childNodes.length-1
	for i = 0 to ChildrenCount
'		if not (playerXML.item(i).childNodes.length<5)  then

			playerName = playerXML.item(i).childNodes.item(0).text
			playerRace = playerXML.item(i).childNodes.item(1).text
			playerClass = playerXML.item(i).childNodes.item(2).text
			playerLevel = playerXML.item(i).childNodes.item(3).text
			playerJoinTime = playerXML.item(i).childNodes.item(4).text

		'有表单数据就覆盖旧缓存文件
		if not (request.form("xmltext")="") then
			Call WriteFile ("CTRT_"&time_type(playerJoinTime,3)&".xml",request.form("xmltext"))
		end if

			Response.write "<tr class='"&linec(i)&"'><td>"&i+1&"</td><td>"&playerName&"</td><td>"&playerRace&"</td>"
			Response.write "<td>"&ClassConvert(playerClass)&"</td><td>"&playerLevel&"</td><td>"&playerJoinTime&"</td></tr>"&vbCrlf

				'@@@@@@@@@@@@@
				sql="select * from player where player_name='"&playerName&"'"
				rs.open sql,conn,1,3
					if rs.eof or rs.bof then
						rs.close
						sql="select * from player where (id is null)"
						rs.open sql,conn,1,3
						rs.addnew
							rs("player_name")=playerName
							rs("player_level")=playerLevel
							rs("player_tribe")=playerRace
							rs("player_profession")=ClassConvert(playerClass)
							rs("player_honor")="无"
							rs("player_jointime")=DateValue(rtXML.childNodes.item(0).text)
							rs("player_BaseDKP")=0
							rs("player_DKP")=0
							rs("player_skill_1")="未知"
							rs("player_skill_2")="未知"
						rs.update
	'					response.write "职业:"&ClassConvert(playerClass)
	'				response.write "<br>添加新成员: "&playerName	
					else
						if rs("player_level")<>playerLevel or rs("player_tribe")<>playerRace or rs("player_profession")<>ClassConvert(playerClass) then
							rs("player_name")=playerName
	'						rs("player_level")=playerLevel
							rs("player_tribe")=playerRace
							rs("player_profession")=ClassConvert(playerClass)
							rs.update
	'						response.write "<br>成员:"&playerName&" 的资料已更新"
						end if
					end if
				rs.close

	'++++++++++++ 成员加入事件写入
	if DateDiff("n",CDate(playerJoinTime),DateAdd("n",30,CDate(rtXML.childNodes.item(0).text)))<0 then
	rs2.addnew
	rs2("event_raidid")=RaidID
	rs2("event_time")=playerJoinTime
	rs2("event_class")="加入"
	rs2("event_dkp")=0
	rs2("event_object")=name2id(playerName)
	rs2("event_object2")=""
	rs2.update
	end if

'		end if
	next
	rs2.close

	'****获取数据库中对应玩家ID
	arrPlayerList = Split(Mid(left(arrPlayerList,len(arrPlayerList)-1),2),",")
	ReDim arrPlayerListNum(UBound(arrPlayerList))
	sql="select * from player"
	rs.open sql,conn,1,1
	for i = 1 to rs.recordcount
		for j = 0 to UBound(arrPlayerList)
			if rs("player_name")=arrPlayerList(j) then
			arrPlayerListNum(j)=rs("id")
			end if
		next
		rs.movenext
	next
	rs.close
	'****
	'&&&&添加成员
	sql = "select * from raid where id="&RaidID
	rs.open sql,conn,1,3
	rs("raid_player")=join(arrPlayerListNum,", ")
	rs.update
	rs.close
	'&&&&


	Response.write "</table>"&vbCrlf
End Sub


Sub CTRT_Leave() '离开相关处理|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
	Response.write "<table class='dkplist'>"&vbCrlf
	Response.write "<tr><th colspan='3'>Raid Leave List</th></tr>"&vbCrlf

	Response.write "<tr><th>Number</th><th>Name</th><th>最后离开时间</th></tr>"&vbCrlf

' arrLeavePlayerList , arrLeavePlayerTime
'-----------------清理玩家离开表中重复的和信息不全的条目
	ChildrenCount = leaveplayerXML.length-1
	arrLeavePlayerList=","
	arrLeavePlayerTime=","
	Dim iz
	for i = 0 to ChildrenCount
		iz=ChildrenCount-i
		if leaveplayerXML.item(iz).childNodes.length<2 then
			rtXML.childNodes.item(3).removeChild(leaveplayerXML.item(iz))
			ChildrenCount=ChildrenCount-1
			i=i-1
		else
			if Instr(arrLeavePlayerList,","&leaveplayerXML.item(iz).childNodes.item(0).text&",")>0 then
				rtXML.childNodes.item(3).removeChild(leaveplayerXML.item(iz))
				ChildrenCount=ChildrenCount-1
				i=i-1
			else
				arrLeavePlayerList = ","&leaveplayerXML.item(iz).childNodes.item(0).text&arrLeavePlayerList
				arrLeavePlayerTime = ","&leaveplayerXML.item(iz).childNodes.item(0).text&arrLeavePlayerTime
			end if
		end if
		if i=ChildrenCount then exit for
	next
'-----------------清理结束
	Sql="Select * from raid_event where (id is null)"
	rs2.open sql,conn,1,3
	ChildrenCount = leaveplayerXML.length-1
	for i = 0 to ChildrenCount
		if not (leaveplayerXML.item(i).childNodes.length<2) then
		leavePlayerName = rtXML.childNodes.item(3).childNodes.item(i).childNodes.item(0).text
		leavePlayerTime = rtXML.childNodes.item(3).childNodes.item(i).childNodes.item(1).text
		Response.write "<tr class='"&linec(i)&"'><td>"&i+1&"</td><td>"&leavePlayerName&"</td><td>"&leavePlayerTime&"</td></tr>"&vbCrlf

			if DateDiff("n",CDate(leavePlayerTime),RaidEndTime)>5 then
			Response.write "333"&leavePlayerName
				if CheckLeaveTime(leavePlayerName,leavePlayerTime) then
					rs2.addnew
					rs2("event_raidid")=RaidID
					rs2("event_time")=leavePlayerTime
					rs2("event_class")="离开"
					rs2("event_dkp")=0
					rs2("event_object")=name2id(leavePlayerName)
					rs2("event_object2")=""
					rs2.update
				end if
			end if
		
		end if


	next
	rs2.close

	Response.write "</table>"&vbCrlf

End Sub


Sub CTRT_Loot() '物品相关处理|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
	Response.write "<table class='dkplist'>"&vbCrlf
	Response.write "<tr><th colspan='8'>Raid Item Drop</th></tr>"&vbCrlf
	Response.write "<tr><th>Number</th><th>Item</th><th>ItemCode</th><th>Level</th><th>Count</th><th>Looter</th><th>LootTime</th><th>Note/DKP</th></tr>"&vbCrlf
	ChildrenCount = rtXML.childNodes.item(4).childNodes.length-1

	'^^^^^^^^^写入数据库
	Sql="Select * from raid_event where (id is null)"
	rs.open sql,conn,1,3

		for i = 0 to ChildrenCount
			if not (LootXML.item(i).childNodes.length<7) then
				itemName = LootXML.item(i).childNodes.item(0).text
				itemID = LootXML.item(i).childNodes.item(1).text
				itemColor = LootXML.item(i).childNodes.item(2).text
				itemCount = LootXML.item(i).childNodes.item(3).text
				itemLooter = LootXML.item(i).childNodes.item(4).text
				itemLootTime = LootXML.item(i).childNodes.item(5).text
				itemNote = LootXML.item(i).childNodes.item(6).text
				Response.write "<tr class='"&linec(i)&"'><td>"&i+1&"</td><td>"&itemName&"</td><td>"&itemID&"</td><td>"&itemColor&"</td>"
				Response.write "<td>"&itemCount&"</td><td>"&itemLooter&"</td><td>"&itemLootTime&"</td><td>"&itemNote&"</td></tr>"&vbCrlf

	rs.addnew
	rs("event_raidid")=RaidID
	rs("event_time")=itemLootTime

		if IsNumeric(itemNote) then
			rs("event_class")="拾取"
			rs("event_dkp")=CInt(itemNote)
		elseif UCase(itemNote)="BOE" then
			rs("event_class")="仓库"
			rs("event_dkp")=40
		elseif UCase(itemNote)="ENC" then
			rs("event_class")="分解"
			rs("event_dkp")=0
		else
			rs("event_class")="分解"
			rs("event_dkp")=0
		end if

	rs("event_object")=name2id(itemLooter)
	rs("event_object2")=itemName

	rs.update
			
			end if
		next
	rs.close
	'^^^^^^^^^	


		Response.write "</table>"&vbCrlf


End Sub


Sub FSDKP_Event() '处理Raid其他事件
	On Error Resume Next
	Set EventXML=rXML.getElementsByTagName("Event")(0).childNodes

	ChildrenCount = EventXML.length-1
	'^^^^^^^^^RAID事件写入数据库
	Sql="Select * from raid_event where (id is null)"
	rs.open sql,conn,1,3
		for i = 0 to ChildrenCount
			Ex_EventClass = EventXML.item(i).childNodes.item(0).text
			Ex_Player = EventXML.item(i).childNodes.item(1).text
			Ex_Event = EventXML.item(i).childNodes.item(2).text
			Ex_Time = EventXML.item(i).childNodes.item(3).text
			Response.write "1"

			rs.addnew
				rs("event_raidid")=RaidID
				rs("event_time")=Ex_Time
				rs("event_class")=Ex_EventClass
				rs("event_object")=Ex_Player
				rs("event_object2")=Ex_Event
			rs.update
		next
	rs.close
	'^^^^^^^^^	
End Sub

Sub WriteFile (strFilename,strFileText) 
   Set fso = CreateObject("Scripting.FileSystemObject") 
   Set f = fso.CreateTextFile(Server.MapPath("xml/"&strFilename))
   f.writeline(strFileText)
   f.close
   set fso = Nothing
end sub

function DateE2C(d)
	dim arrD
	arrD=split(d,"/")
	DateE2C="20"&left(arrD(2),2)&"-"&arrD(0)&"-"&arrD(1)&" "&Mid(arrD(2),4)
end function

function checkPR(n)
	
end function


Function CheckLeaveTime(cname,ctime)
	Dim CCount
	CheckLeaveTime = True
	CCount = stXML.childNodes.item(2).childNodes.length-1
	'response.write "----------N:"&cname&" ----- T:"&ctime&"---------<br>"
	for ik = 0 to CCount
		'if not (playerXMLs.item(ik).childNodes.length<5)  then
			if cname=playerXMLs.item(ik).getElementsByTagName("player")(0).text and DateDiff("n",CDate(playerXMLs.item(ik).getElementsByTagName("time")(0).text),ctime)<0 then
				'response.write cname&" - "&playerXMLs.item(ik).childNodes.item(0).text&"<BR>"
				'response.write ctime&" - "&CDate(DateE2C(playerXMLs.item(ik).childNodes.item(4).text))&"| "
				'response.write DateDiff("n",CDate(DateE2C(playerXMLs.item(ik).childNodes.item(4).text)),ctime)&"<BR>"

			'	response.write "N:"&playerXMLs.item(ik).childNodes.item(0).text&" T:"&DateE2C(playerXMLs.item(ik).childNodes.item(4).text)&"<br>"
				CheckLeaveTime = False
				exit function
			else
			'	response.write ">>N:"&playerXMLs.item(ik).childNodes.item(0).text&" T:"&DateE2C(playerXMLs.item(ik).childNodes.item(4).text)&"<br>"
			end if
		'end if
	next
End Function
%>